package com.fzfnn.scrapbook.controller;

import com.fzfnn.scrapbook.entity.Comment;
import com.fzfnn.scrapbook.service.CommentService;
import com.fzfnn.scrapbook.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/journal/comments")
@Tag(name = "评论接口", description = "评论相关接口")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping("/add")
    @Operation(summary = "添加评论")
    public R addComment(@RequestBody Comment comment,@RequestHeader("Authorization") String token) {
        return commentService.addComment(comment, token);
    }

    @GetMapping("/journal/{journalId}")
    @Operation(summary = "获取评论,支持嵌套")
    public R getComments(@PathVariable Long journalId) {
        return commentService.getNestedCommentsByJournalId(journalId);
    }

    @DeleteMapping("/{commentId}")
    @Operation(summary = "删除评论")
    public R deleteComment(@PathVariable Long commentId,
                           @RequestHeader("Authorization") String token) {
        return commentService.deleteComment(commentId, token);
    }
}

